package com.climb.moive.controller;

import com.climb.moive.framework.mvc.BaseController;
import com.climb.moive.service.MovieEvalService;
import com.climb.moive.service.MovieReviewService;
import com.climb.moive.service.impl.MoiveEvalServiceImpl;
import com.climb.moive.service.impl.MovieReviewServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/adminEvaluation")
public class AdminEvaluationController extends BaseController {
    MovieEvalService evalService=new MoiveEvalServiceImpl();
    MovieReviewService reviewServic=new MovieReviewServiceImpl();
    @Override
    public String index(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*获取movieEvaluationList发给前台*/
        req.setAttribute("movieEvaluationList", evalService.findAllEvaluation());
        return "forward:/view/admin/AdminMovieEvaluationManagement.jsp";
    }
    /**删除短评*/
    public String delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id=Integer.valueOf(req.getParameter("id"));
        /*执行删除*/
        evalService.deleteByEid(id);
        /*返回列表*/
        return index(req,resp);
    }
    /**查看短评*/
    public String details(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*获取id*/
        Integer id=Integer.valueOf(req.getParameter("id"));
        /*获取对象evaluation并传值*/
        req.setAttribute("evaluation",evalService.findEvaByEid(id));
        return "forward:/view/admin/AdminMovieEvaluationDetail.jsp";
    }
    /**文章列表*/
    public String indexReview(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*获取movieReviewList发给前台*/
        req.setAttribute("movieReviewList", reviewServic.findAllReview());
        return "forward:/view/admin/AdminMovieReviewList.jsp";
    }
    /**删除文章*/
    public String deleteReview(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id=Integer.valueOf(req.getParameter("id"));
        /*执行删除*/
        reviewServic.deleteByRid(id);
        /*返回列表*/
        return indexReview(req,resp);
    }
    /**查看文章*/
    public String detailsReview(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id=Integer.valueOf(req.getParameter("id"));
        /*获取对象movieReview并传值*/
        req.setAttribute("movieReview",reviewServic.findReviewByRid(id));
        return "forward:/view/admin/AdminMovieReviewDetail.jsp";
    }
}
